<template>
	<section>
		<!--  工具条 -->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.name" placeholder="姓名"></el-input>
				</el-form-item >
					<el-date-picker
							v-model="dateValue1"
							type="daterange"
							align="right"
							unlink-panels
							range-separator="  -- 至 --  "
							placeholder="选择开始日期和结束日期"
							:picker-options="pickerOptions"
					style="width: 260px">
					</el-date-picker>
				<el-form-item>
					<el-button type="primary" v-on:click="getListData">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="showAdd">新增</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--  列表 -->
		<el-table :data="listData" highlight-current-row v-loading="listLoading" @selection-change="colsChange" style="width: 100%;" >
			<el-table-column type="selection" width="50">
			</el-table-column>
			<el-table-column type="index" width="50" fixed>
			</el-table-column>
			<el-table-column prop="name" label="客户姓名"  width="120" sortable fixed>
			</el-table-column>
			<el-table-column prop="age" label="年龄" width="100" sortable>
			</el-table-column>
			<el-table-column prop="gender" label="性别" width="100" sortable :formatter="formatSex">
			</el-table-column>
			<el-table-column prop="tel" label="电话号码" width="150" sortable>
			</el-table-column>
			<el-table-column prop="email" label="邮箱" width="150" sortable>
			</el-table-column>
			<el-table-column prop="qq" label="QQ" width="150" sortable>
			</el-table-column>
			<el-table-column prop="wechat" label="微信" width="150" sortable>
			</el-table-column>
			<el-table-column prop="job_id.name" label="客户职业" width="120" sortable>
			</el-table-column>
			<el-table-column prop="salaryLevel_id.name" label="收入水平" width="120" sortable>
			</el-table-column>
			<el-table-column prop="customerSource_id.name" label="客户来源" width="120" sortable>
			</el-table-column>
			<el-table-column prop="seller_id.username" label="市场专员" width="120" sortable>
			</el-table-column>
			<el-table-column prop="inputUser_id.username" label="创建人" width="150" sortable>
			</el-table-column>
			<el-table-column prop="inputTime" label="创建时间" width="200" sortable>
			</el-table-column>
			<el-table-column prop="tenant_id.companyName" label="所属租户" width="150" sortable>
			</el-table-column>
			<el-table-column prop="status" label="状态" width="120" sortable >
				<template scope="scope">
					<span v-if="scope.row.status == 0" style="color: #11b95c">初始录入</span>
					<span v-else-if="scope.row.status == 1" style="color: #f7ba2a">跟进中</span>
					<span v-else-if="scope.row.status == 2" style="color: #e64242">无法跟进</span>
					<span v-else style="color: dimgrey">未知</span>
				</template>
			</el-table-column>
			<el-table-column label="功能" width="280" fixed="right" header-align="center" align="center">
				<template scope="scope">
					<div :hidden="scope.row.status===2" >
					<el-popover
							placement="top-start"
							width="250"
							trigger="hover"
							content="跟进客户，记录下收集资料的每个细节">
						<el-button type="success" size="small" slot="reference"
								   @click="showMove(scope.$index, scope.row)"
						>跟进</el-button>
					</el-popover>
					<el-popover
							placement="top-start"
							width="260"
							trigger="hover"
							content="把客户从一个市场专员手里交给另一个市场专员">
						<el-button type="warning" size="small" slot="reference"
								   @click="showTransfer(scope.$index, scope.row)">移交</el-button>
					</el-popover>
					<el-popover
							placement="top-start"
							width="260"
							trigger="hover"
							content="将客户移入到资源池中,资源池相当于回收站">
						<el-button type="danger" size="small" slot="reference" @click="moveToPool(scope.row)" >放入资源池</el-button>
					</el-popover>
					</div>
					<div :hidden="scope.row.status!=2">
					<el-button type="primary" size="small" slot="reference" @click="moveOutPool(scope.row)" >移出资源池</el-button>
					</div>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="200" fixed="right" header-align="center" align="center">
				<template scope="scope">
					<el-button size="small" @click="showEdit(scope.$index, scope.row)" :disabled="scope.row.status===2">编辑</el-button>
					<el-button type="danger" size="small" @click="delSubmit(scope.$index, scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--  新增界面 -->
		<el-dialog title="新增" v-model="addFormOn" :close-on-click-modal="false" align="left">
			<el-form :model="addForm2" label-width="80px" :rules="addForm1" ref="addForm2">
				<el-form-item label="客户姓名" prop="name" >
					<el-input v-model="addForm2.name" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="客户年龄" prop="age" >
					<el-input v-model.number="addForm2.age" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="客户性别" prop="gender" >
					<el-radio-group v-model.number="addForm2.gender">
						<el-radio :label="1">男</el-radio>
						<el-radio :label="0">女</el-radio>
						<el-radio :label="2">未知</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="电话号码" prop="tel" >
					<el-input v-model="addForm2.tel" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="邮箱" prop="email" >
					<el-input v-model="addForm2.email" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="qq" prop="qq" >
					<el-input v-model="addForm2.qq" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="微信" prop="wechat" >
					<el-input v-model="addForm2.wechat" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="职业" prop="job_id" >
					<el-select v-model.number="addForm2.job_id.id" placeholder="请选择" >
						<el-option
								v-for="k in jobsAll"
								:key="k.id"
								:label="k.name"
								:value="k.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="收入水平" prop="salaryLevel_id" >
					<el-select v-model.number="addForm2.salaryLevel_id.id" placeholder="请选择" >
						<el-option
								v-for="k in salaryAll"
								:key="k.id"
								:label="k.name"
								:value="k.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="客户来源" prop="customerSource_id">
					<el-select v-model.number="addForm2.customerSource_id.id" placeholder="请选择" >
						<el-option
								v-for="k in cusSourceAll"
								:key="k.id"
								:label="k.name"
								:value="k.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="市场专员" prop="seller_id">
					<el-select v-model.number="addForm2.seller_id.id" placeholder="请选择" >
						<el-option
								v-for="k in sellerAll"
								:key="k.id"
								:label="k.username"
								:value="k.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="addFormOn = false">取消</el-button>
				<el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
			</div>
		</el-dialog>

		<!--  编辑界面 -->
		<el-dialog title="编辑" v-model="editFormOn" :close-on-click-modal="false" align="left">
			<el-form :model="editForm2" label-width="80px" :rules="editForm1" ref="editForm2">
				<el-form-item label="客户姓名" prop="name" >
					<el-input v-model="editForm2.name" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="客户年龄" prop="age" >
					<el-input v-model.number="editForm2.age" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="客户性别" prop="gender" >
					<el-radio-group v-model.number="editForm2.gender">
						<el-radio :label="1">男</el-radio>
						<el-radio :label="0">女</el-radio>
						<el-radio :label="2">未知</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="电话号码" prop="tel" >
					<el-input v-model="editForm2.tel" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="邮箱" prop="email" >
					<el-input v-model="editForm2.email" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="qq" prop="qq" >
					<el-input v-model="editForm2.qq" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="微信" prop="wechat" >
					<el-input v-model="editForm2.wechat" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="职业" prop="job_id" >
					<el-select v-model.number="editForm2.job_id.id" placeholder="请选择" >
						<el-option
								v-for="k in jobsAll"
								:key="k.id"
								:label="k.name"
								:value="k.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="收入水平" prop="salaryLevel_id" >
					<el-select v-model.number="editForm2.salaryLevel_id.id" placeholder="请选择" >
						<el-option
								v-for="k in salaryAll"
								:key="k.id"
								:label="k.name"
								:value="k.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="客户来源" prop="customerSource_id">
					<el-select v-model.number="editForm2.customerSource_id.id" placeholder="请选择" >
						<el-option
								v-for="k in cusSourceAll"
								:key="k.id"
								:label="k.name"
								:value="k.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="市场专员" prop="seller_id">
					<el-select v-model.number="editForm2.seller_id.id" placeholder="请选择" >
						<el-option
								v-for="k in sellerAll"
								:key="k.id"
								:label="k.username"
								:value="k.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormOn = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>

		<!--  跟进界面 -->
		<el-dialog title="跟进" v-model="moveFormOn" :close-on-click-modal="false" align="left">
			<el-form :model="moveForm2" label-width="80px" :rules="moveForm1" ref="moveForm2">
				<el-form-item label="跟进方式" prop="traceType_id" >
					<el-select v-model.number="moveForm2.traceType_id.id" placeholder="请选择" >
						<el-option
								v-for="k in moveTypeAll"
								:key="k.id"
								:label="k.name"
								:value="k.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="跟进效果" prop="traceResult" >
                    <el-radio-group v-model.number="moveForm2.traceResult">
                        <el-radio :label="0" >优</el-radio>
                        <el-radio :label="1" >良</el-radio>
                        <el-radio :label="2" >差</el-radio>
                    </el-radio-group>
				</el-form-item>
				<el-form-item label="跟进主题" prop="title" >
					<el-input v-model="moveForm2.title" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
				<el-form-item label="备注" prop="remark" >
					<el-input v-model="moveForm2.remark" type="textarea" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="moveFormOn = false">取消</el-button>
				<el-button type="primary" @click.native="moveSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>

		<!--  移交界面 -->
		<el-dialog title="移交" v-model="transferFormOn" :close-on-click-modal="false" align="left">
			<el-form :model="transferForm2" label-width="80px" :rules="transferForm1" ref="transferForm2">
				<el-form-item label="新的市场专员" prop="newSeller_idName" label-width="120px">
					<el-select v-model.number="transferForm2.newSeller_idName" placeholder="请选择" >
						<el-option
								v-for="k in newSellerAll"
								:key="k.id"
								:label="k.username"
								:value="k.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="备注" prop="transReason" label-width="120px" >
					<el-input v-model="transferForm2.transReason" type="textarea" auto-complete="off" style="width: 50%" ></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="transferFormOn = false">取消</el-button>
				<el-button type="primary" @click.native="transferSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>


		<!--  工具条 -->
		<el-col :span="24" class="toolbar" >
			<el-button type="danger" @click="batchRemove" :disabled="this.cols.length===0" >批量删除</el-button>
			<el-pagination layout="prev, pager, next" @current-change="showCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
	</section>
</template>

<script>
    import util from '../../../common/js/util';
    import { getUserListPage, removeUser, batchRemoveUser, editUser, addUser } from '../../../api/api';
    import ElRadioButton from "element-ui/packages/radio/src/radio-button";

    export default {
        components: {ElRadioButton},
        data() {
            return{
                filters: {
                    name: ''
                },
                listData: [],
                keyword:'',
                pageSize: 10,
                currentPage:1,
                listLoading : false,
				hiddenAll:true,
				hiddenOne:false,

				//移入资源池等待
                moveToPoolLoading:false,
				//资源池表格
                mtpForm: {
                },

                //移出资源池等待
                moveOutPoolLoading:false,
                //资源池移出表格
                mopForm: {
                },


                //列表选中的列
                cols: [],

                //职业的下拉框
                jobsLoading:false,
                jobsAll:[],

                //收入水平的下拉框
                salaryLoading:false,
                salaryAll:[],

                //客户来源的下拉框
                cusSourceLoading:false,
                cusSourceAll:[],

                //市场专员的下拉框
                sellerLoading:false,
                sellerAll:[],

                //跟进方式的下拉框
                moveTypeLoading:false,
                moveTypeAll:[],

                //新的市场专员的下拉框 去重的处理
                newSellerAll:[],

                //新增界面是否显示
                addFormOn: false,
                //新增等待界面
                addLoading: false,
                //新增表格
                addForm1: {
                    name: [
                        { required: true, message: '客户姓名不能为空', trigger: 'blur' }
                    ],
                    age: [
                        { required: true, type: 'number', message: '年龄不能为空且必须为数字',trigger: 'blur' }
                    ],
                    gender: [
                        { required: true,type: 'number', message: '性别不能为空', trigger: 'blur' }
                    ],
                    tel: [
                        { required: true, message: '电话号码不能为空', trigger: 'blur' }
                    ],
                    email: [
                        { required: false, message: '邮箱', trigger: 'blur' }
                    ],
                    qq: [
                        { required: false, message: 'qq', trigger: 'blur' }
                    ],
                    wechat: [
                        { required: false, message: '微信', trigger: 'blur' }
                    ]
                },
                //新增界面空表格
                addForm2: {
                    name:'',
                    age:0,
                    gender:1,
                    tel:'',
                    email:'',
                    qq:'',
                    wechat:'',
                    job_id:{
                        id:'',
                    },
                    salaryLevel_id:{
                        id:'',
                    },
                    customerSource_id:{
                        id:'',
                    },
                    seller_id:{
                        id:'',
                    },
                    inputUser_id:{
                        id:'',
                    },
                    inputTime:new Date(),
                    tenant_id:{
                        id:'',
                    },
                    status:0,
                },

                //编辑界面是否显示
                editFormOn: false,
                //编辑等待界面
                editLoading: false,
                //编辑表格
                editForm1: {
                    name: [
                        { required: true, message: '客户姓名不能为空', trigger: 'blur' }
                    ],
                    age: [
                        { required: true, type: 'number', message: '年龄不能为空且必须为数字',trigger: 'blur' }
                    ],
                    gender: [
                        { required: true,type: 'number', message: '性别不能为空', trigger: 'blur' }
                    ],
                    tel: [
                        { required: true, message: '电话号码不能为空', trigger: 'blur' }
                    ],
                    email: [
                        { required: false, message: '邮箱', trigger: 'blur' }
                    ],
                    qq: [
                        { required: false, message: 'qq', trigger: 'blur' }
                    ],
                    wechat: [
                        { required: false, message: '微信', trigger: 'blur' }
                    ]
                },
                //编辑界面空表格
                editForm2: {
                    name:'',
                    age:0,
                    gender:1,
                    tel:'',
                    email:'',
                    qq:'',
                    wechat:'',
                    job_id:{
                        id:'',
                    },
                    salaryLevel_id:{
                        id:'',
                    },
                    customerSource_id:{
                        id:'',
                    },
                    seller_id:{
                        id:'',
                    },
                    inputUser_id:{
                        id:'',
                    },
                    inputTime:new Date(),
                    tenant_id:{
                        id:'',
                    },
                    status:0,
                },


                //跟进界面是否显示
                moveFormOn: false,
                //跟进等待界面
                moveLoading: false,
                //跟进表格
                moveForm1: {
                    traceResult: [
                        { required: false,type: 'number', message: '跟进效果',trigger: 'blur' }
                    ],
                    title: [
                        { required: false, message: '跟进主题', trigger: 'blur' }
                    ],
                    remark: [
                        { required: false, message: '备注', trigger: 'blur' }
                    ]
                },
                //跟进界面空表格
                moveForm2: {
                    customer_id:{
                        id:'',
					},
                    traceUser_id:{
                        id:'',
					},
                    traceTime:new Date(),
                    traceType_id:{
                        id:'',
                    },
                    traceResult:'',
                    title:'',
                    remark:'',
                    tenant_id:{
                        id:'',
					},
                },


                //移交界面是否显示
                transferFormOn: false,
                //移交等待界面
                transferLoading: false,
                //移交表格
                transferForm1: {
                    newSeller_idName: [
                        { required: true,type: 'number', message: '选择一位新的市场专员',trigger: 'blur' }
                    ],
                    transReason: [
                        { required: false, message: '移交理由', trigger: 'blur' }
                    ]
                },
                //移交界面空表格
                transferForm2: {
                    customer_id:{},
                    transUser_idName:'',
                    transTime:new Date(),
                    oldSeller_id:{},
                    newSeller_idName:'',
                    transReason:'',
                    tenant_id:{},
                },


				//日期查询
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                dateValue1: '',
            };
		},
        methods: {
            formatSex:function (row) {
                return row.gender == 1 ? '男' : row.gender == 0 ? '女' : '未知';
            },

            formatStatus:function (row) {
                if(row.status == 0){
                    return '初始录入';
				}else if(row.status == 1){
                    return '无法跟进';
				}else if(row.status == 2){
                    return '跟进中';
				}else {
                    return '未知';
				}
            },


            getListData() {
				let para = {
                    currentPage: this.currentPage,
                    pageSize:this.pageSize,
                    keyword: this.filters.name,
					date1:this.dateValue1[0],
                    date2:this.dateValue1[1],
                };
                this.listLoading = true;
                this.$http.post('/customer/findByPage',para).then(res=>{
                    let ajaxResult =  res.data;
                    if (ajaxResult.success){
                        this.listData = ajaxResult.data.result;
                        this.total = ajaxResult.data.total
                    }else {
                        this.$message({
                            message: '加载失败',
                            type: 'error'
                        });
                    }
                    this.listLoading = false;
                }).catch(error=>{
                    this.listLoading = false;
                    this.$message({
                        message: '加载失败',
                        type: 'error'
                    });
                })
            },


            //新增的界面
            showAdd:function () {

                this.addFormOn = true;
                this.addForm2 = {
                    name:'',
                    age:0,
                    gender:1,
                    tel:'',
                    email:'',
                    qq:'',
                    wechat:'',
                    job_id:{
                        id:'',
                    },
                    salaryLevel_id:{
                        id:'',
                    },
                    customerSource_id:{
                        id:'',
                    },
                    seller_id:{
                        id:'',
                    },
                    inputUser_id:{
                        id:'',
                    },
                    inputTime:new Date(),
                    tenant_id:{
                        id:'',
                    },
                    status:0,
                };
                this.addForm2.inputUser_id.id = JSON.parse(sessionStorage.getItem('user')).id;
            },
            //新增的方法
            addSubmit:function () {
                this.$refs.addForm2.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.addLoading = true;
                            let para = Object.assign({}, this.addForm2);
                            console.debug(para);
                            this.$http.post('/customer/insert',para).then(res =>{
                                let ajaxResult = res.data;
                                if (ajaxResult.success){
                                    this.$message.success("添加成功");
                                    this.addFormOn = false;
                                    this.$refs['addForm2'].resetFields();
                                    this.getListData();
                                }else {
                                    this.addFormOn = false;
                                    this.$message({
                                        message: '添加失败',
                                        type: 'error'
                                    });
                                }
                                this.addLoading = false;
                            }).catch(error =>{
                                this.addLoading = false;
                                this.$message({
                                    message: '添加失败',
                                    type: 'error'
                                });
                            })
                        });
                    }
                });
            },


            //编辑的界面
            showEdit:function (index,row) {
                this.editFormOn = true;
                this.editForm2 = Object.assign({}, row);
            },
            //编辑的方法
            editSubmit:function () {
                this.$refs.editForm2.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认提交吗？', '提示', {}).then(() => {
                            this.editLoading = true;
                            let para = Object.assign({}, this.editForm2);
                            this.$http.post('/customer/updateAll',para).then(res =>{
                                let ajaxResult = res.data;
                                if (ajaxResult.success){
                                    this.$message.success("修改成功");
                                    this.editFormOn = false;
                                    this.$refs['editForm2'].resetFields();
                                    this.getListData();
                                }else {
                                    this.editFormOn = false;
                                    this.$message({
                                        message: '修改失败1',
                                        type: 'error'
                                    });
                                }
                                this.editLoading = false;
                            }).catch(error =>{
                                this.editLoading = false;
                                this.$message({
                                    message: '修改失败2',
                                    type: 'error'
                                });
                            })
                        });
                    }
                });
            },

            //删除
            delSubmit: function (index, row) {
                this.$confirm('确认删除吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    this.$http.delete('/customer/delete/'+row.id,{}).then(res=>{
                        let ajaxResult =  res.data
                        if (ajaxResult.success){
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            this.getListData();
                        }else {
                            this.$message({
                                message: '删除失败',
                                type: 'error'
                            });
                        }
                        this.listLoading = false;
                    }).catch(error=>{
                        this.listLoading = false;
                        this.$message({
                            message: '删除失败',
                            type: 'error'
                        });
                    })

                });
            },

            //显示当前的页数
            showCurrentChange(val) {
                this.currentPage=val;
                this.getListData();
            },

            colsChange: function (cols) {
                this.cols = cols;
            },

            //批量删除
            batchRemove: function () {
                var ids = this.cols.map(item => item.id)
                this.$confirm('确认删除选中记录吗？', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    let para = { ids: ids };
                    this.$http.post("/customer/batchDelete",para).then(res=>{
                        let ajaxResult = res.data;
                        if (ajaxResult.success){
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            this.getListData();
                        }else {
                            this.$message({
                                message: '删除失败',
                                type: 'error'
                            });
                        }
                        this.listLoading = false;
                    }).catch(error => {
                        this.listLoading = false;
                        this.$message({
                            message: '删除失败',
                            type: 'error'
                        });
                    })

                })
            },


            //跟进的界面
            showMove:function (index,row) {
                this.moveFormOn = true;
                this.moveForm2 = {
                    customer_id:{
                        id:'',
                    },
                    traceUser_id:{
                        id:'',
                    },
                    traceTime:new Date(),
                    traceType_id:{
                        id:'',
                    },
                    traceResult:'',
                    title:'',
                    remark:'',
                    tenant_id:{
                        id:'',
                    },
                };
                this.moveForm2.customer_id.id = row.id;
                this.moveForm2.traceUser_id = row.seller_id;
                this.moveForm2.tenant_id = row.tenant_id;
            },
            //跟进的方法
            moveSubmit:function () {
                this.$refs.moveForm2.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认跟进吗？', '提示', {}).then(() => {
                            this.moveLoading = true;
                            let para = Object.assign({}, this.moveForm2);
                            console.debug(para);
                            this.$http.post('/cusTraHistory/moveCus/'+para.customer_id.id
                                ,para).then(res =>{
                                let ajaxResult = res.data;
                                if (ajaxResult.success){
                                    this.$message.success("跟进成功");
                                    this.moveFormOn = false;
                                    this.$refs['moveForm2'].resetFields();
                                    this.getListData();
                                }else {
                                    this.moveFormOn = false;
                                    this.$message({
                                        message: '跟进失败1',
                                        type: 'error'
                                    });
                                }
                                this.moveLoading = false;
                            }).catch(error =>{
                                this.moveLoading = false;
                                this.$message({
                                    message: '跟进失败2',
                                    type: 'error'
                                });
                            })
                        });
                    }
                });
            },

            //移交的界面
            showTransfer:function (index,row) {
                this.transferFormOn = true;
                this.transferForm2 = {
                    customer_id:{},
                    transUser_idName:JSON.parse(sessionStorage.getItem('user')).id,
                    transTime:new Date(),
                    oldSeller_id:{},
                    newSeller_idName:'',
                    transReason:'',
                    tenant_id:{},
                };
                this.transferForm2.customer_id.id = row.id;
                this.transferForm2.oldSeller_id = row.seller_id;
                this.transferForm2.tenant_id = row.tenant_id;
                this.loadNewEmp(row);

            },

            //移交的方法
            transferSubmit:function () {
                this.$refs.transferForm2.validate((valid) => {
                    if (valid) {
                        this.$confirm('确认移交吗？', '提示', {}).then(() => {
                            this.transferLoading = true;
                            let para = Object.assign({}, this.transferForm2);
                            this.$http.post('/cusTransfer/transfer/'+para.customer_id.id
								+'/'+para.newSeller_idName+'/'+para.transUser_idName
                                ,para).then(res =>{
                                let ajaxResult = res.data;
                                if (ajaxResult.success){
                                    this.$message.success("跟进成功");
                                    this.transferFormOn = false;
                                    this.$refs['transferForm2'].resetFields();
                                    this.getListData();
                                }else {
                                    this.transferFormOn = false;
                                    this.$message({
                                        message: '跟进失败1',
                                        type: 'error'
                                    });
                                }
                                this.transferLoading = false;
                            }).catch(error =>{
                                this.transferLoading = false;
                                this.$message({
                                    message: '跟进失败2',
                                    type: 'error'
                                });
                            })
                        });
                    }
                });
            },


            //放入资源池
            moveToPool:function (row) {
                console.debug(row);
				this.$confirm('确认将'+row.name+'放入资源池吗', '提示', {}).then(() => {
                    this.mtpForm = Object.assign({}, row);
					this.moveToPoolLoading = true;
					let para = Object.assign({}, this.mtpForm);
					this.$http.post('/customer/moveToPool',para).then(res =>{
						let ajaxResult = res.data;
						if (ajaxResult.success){
							this.$message.success("移动成功！");
							/*this.$refs['mtpForm'].resetFields();*/
							this.getListData();
						}else {
							this.$message({
								message: '移动失败1',
								type: 'error'
							});
						}
						this.moveToPoolLoading = false;
					}).catch(error =>{
						this.moveToPoolLoading = false;
						this.$message({
							message: '移动失败2',
							type: 'error'
						});
					})
				});
			},

            //移出资源池
            moveOutPool:function (row) {
                this.$confirm('确认将'+row.name+'移出资源池吗', '提示', {}).then(() => {
                    this.mopForm = Object.assign({}, row);
                    this.moveOutPoolLoading = true;
                    let para = Object.assign({}, this.mopForm);
                    this.$http.post('/customer/moveOutPool',para).then(res =>{
                        let ajaxResult = res.data;
                        if (ajaxResult.success){
                            this.$message.success("移动成功！");
                            this.getListData();
                        }else {
                            this.$message({
                                message: '移动失败1',
                                type: 'error'
                            });
                        }
                        this.moveOutPoolLoading = false;
                    }).catch(error =>{
                        this.moveOutPoolLoading = false;
                        this.$message({
                            message: '移动失败2',
                            type: 'error'
                        });
                    })
                });
            },





            //职业的下拉框加载
            loadJobs:function () {
                this.jobsLoading = true;
                this.$http.post('/customer/selectJobs').then(res=>{
                    let ajaxResult =  res.data;
                    if (ajaxResult.success){
                        this.jobsAll = ajaxResult.data;
                    }else {
                        this.$message({
                            message: '加载失败',
                            type: 'error'
                        });
                    }
                    this.jobsLoading = false;
                }).catch(error=>{
                    this.jobsLoading = false;
                    this.$message({
                        message: '加载失败',
                        type: 'error'
                    });
                })
            },

            //收入水平的下拉框加载
            loadSalary:function () {
                this.salaryLoading = true;
                this.$http.post('/customer/selectSalary').then(res=>{
                    let ajaxResult =  res.data;
                    if (ajaxResult.success){
                        this.salaryAll = ajaxResult.data;
                    }else {
                        this.$message({
                            message: '加载失败',
                            type: 'error'
                        });
                    }
                    this.salaryLoading = false;
                }).catch(error=>{
                    this.salaryLoading = false;
                    this.$message({
                        message: '加载失败',
                        type: 'error'
                    });
                })
            },

            //客户来源的下拉框加载
            loadCusSource:function () {
                this.cusSourceLoading = true;
                this.$http.post('/customer/selectCusSource').then(res=>{
                    let ajaxResult =  res.data;
                    if (ajaxResult.success){
                        this.cusSourceAll = ajaxResult.data;
                    }else {
                        this.$message({
                            message: '加载失败',
                            type: 'error'
                        });
                    }
                    this.cusSourceLoading = false;
                }).catch(error=>{
                    this.cusSourceLoading = false;
                    this.$message({
                        message: '加载失败',
                        type: 'error'
                    });
                })
            },

            //市场专员的下拉框加载
            loadSeller:function () {
                this.sellerLoading = true;
                this.$http.post('/customer/selectSeller').then(res=>{
                    let ajaxResult =  res.data;
                    if (ajaxResult.success){
                        this.sellerAll = ajaxResult.data;
                    }else {
                        this.$message({
                            message: '加载失败',
                            type: 'error'
                        });
                    }
                    this.sellerLoading = false;
                }).catch(error=>{
                    this.sellerLoading = false;
                    this.$message({
                        message: '加载失败',
                        type: 'error'
                    });
                })
            },

            //跟进方式的下拉框加载
            loadMoveType:function () {
                this.moveTypeLoading = true;
                this.$http.post('/customer/selectMoveType').then(res=>{
                    let ajaxResult =  res.data;
                    if (ajaxResult.success){
                        this.moveTypeAll = ajaxResult.data;
                    }else {
                        this.$message({
                            message: '加载失败',
                            type: 'error'
                        });
                    }
                    this.moveTypeLoading = false;
                }).catch(error=>{
                    this.moveTypeLoading = false;
                    this.$message({
                        message: '加载失败',
                        type: 'error'
                    });
                })
            },




            loadNewEmp:function (row) {
                this.$http.post('/cusTransfer/newSellerAll/'+row.seller_id.id).then(res=>{
                    let ajaxResult =  res.data;
                    if (ajaxResult.success){
                        this.newSellerAll = ajaxResult.data;
                    }else {
                        this.$message({
                            message: '加载失败',
                            type: 'error'
                        });
                    }
                }).catch(error=>{
                    this.$message({
                        message: '加载失败',
                        type: 'error'
                    });
                })
            },

        },
        mounted() {
            this.getListData();
            this.loadJobs();
            this.loadSalary();
            this.loadCusSource();
            this.loadMoveType();
            this.loadSeller();
        }
    }

</script>

<style scoped>

</style>